package mht.practice.heap;

import mht.practice.sort.SortTestHelper;

import java.util.Arrays;

/**
 * Created by MHT on 2017/8/26.
 */
public class Test {

    // 比较三种 HeapSort 的性能效率
    // 注意, 这几种排序算法都是 O(nlogn) 级别的排序算法
    public static void main(String[] args) {

        int N = 1000000;

        // 测试1 一般性测试
        System.out.println("Test for random array, size = " + N + " , random range [0, " + N + "]");

        Integer[] arr1 = SortTestHelper.generateRandomArray(N, 0, N);
        Integer[] arr2 = Arrays.copyOf(arr1, arr1.length);
        Integer[] arr3 = Arrays.copyOf(arr1, arr1.length);

        SortTestHelper.testSort("mht.practice.heap.HeapSort", arr1);
        SortTestHelper.testSort("mht.practice.heap.HeapSort2", arr2);
        SortTestHelper.testSort("mht.practice.heap.HeapSort3", arr3);

        System.out.println();


        // 测试2 测试近乎有序的数组
        int swapTimes = 100;
        assert swapTimes >= 0;

        System.out.println("Test for nearly ordered array, size = " + N + " , swap time = " + swapTimes);

        arr1 = SortTestHelper.generateNearlyOrderedArray(N, swapTimes);
        arr2 = Arrays.copyOf(arr1, arr1.length);
        arr3 = Arrays.copyOf(arr1, arr1.length);

        SortTestHelper.testSort("mht.practice.heap.HeapSort", arr1);
        SortTestHelper.testSort("mht.practice.heap.HeapSort2", arr2);
        SortTestHelper.testSort("mht.practice.heap.HeapSort3", arr3);

        System.out.println();


        // 测试3 测试存在包含大量相同元素的数组
        System.out.println("Test for random array, size = " + N + " , random range [0,10]");

        arr1 = SortTestHelper.generateRandomArray(N, 0, 10);
        arr2 = Arrays.copyOf(arr1, arr1.length);
        arr3 = Arrays.copyOf(arr1, arr1.length);


        SortTestHelper.testSort("mht.practice.heap.HeapSort", arr1);
        SortTestHelper.testSort("mht.practice.heap.HeapSort2", arr2);
        SortTestHelper.testSort("mht.practice.heap.HeapSort3", arr3);
    }
}
